package com.zxx.otherchaos.widgets.menuItem;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.zxx.otherchaos.R;

import java.util.ArrayList;
import java.util.List;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

public class AdapterActivity extends AppCompatActivity {

    private CircleMenuLayout circleMenuLayout;
    RecyclerView recyclerView;
    private List<Article> articleList;
    private ArticleAdapter adapter;

    private String[] mItemTexts = new String[]{"安全中心", "特色服务", "Android", "信用卡", "我的", "Message",};
    private int[] mItemImgs = new int[]{R.mipmap.ic_launcher_round, R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher, R.mipmap.ic_launcher_round,
            R.mipmap.ic_launcher, R.mipmap.ic_launcher_round,};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_adapter);
        circleMenuLayout = findViewById(R.id.cm_menu_layout);
        //circleMenuLayout.setMenuItemIconsAndTexts(mItemImgs, mItemTexts);
//        circleMenuLayout.setOnItemClickListener(new CircleMenuLayout.OnItemClickListener() {
//            @Override
//            public void onClick(View view, int index) {
//                Toast.makeText(AdapterActivity.this, mItemTexts[index], Toast.LENGTH_SHORT).show();
//            }
//        });
        List<CircleMenuLayout.MenuItem> mMenuItems = new ArrayList<>();
        mMenuItems.add(new CircleMenuLayout.MenuItem(R.mipmap.ic_launcher, "qqqqq"));
        mMenuItems.add(new CircleMenuLayout.MenuItem(R.mipmap.ic_launcher, "AAAAA"));
        mMenuItems.add(new CircleMenuLayout.MenuItem(R.mipmap.ic_launcher, "BBBBB"));
        mMenuItems.add(new CircleMenuLayout.MenuItem(R.mipmap.ic_launcher, "CCCCCCCC"));
        CircleMenuAdapter adapter1 = new CircleMenuAdapter(mMenuItems);
        circleMenuLayout.setAdapter(adapter1);

        recyclerView = findViewById(R.id.recycler_view);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);

        recyclerView.setLayoutManager(staggeredGridLayoutManager);

        recyclerView.setHasFixedSize(true);
        articleList = new ArrayList<>();
        adapter = new ArticleAdapter(this, articleList);
        recyclerView.setAdapter(adapter);

        initData();

        adapter.setmClickListener(new ArticleAdapter.OnItemClickListener<Article>() {
            @Override
            public void onClick(Article article) {
                Log.e("Tag-->", article.title);
                Toast.makeText(AdapterActivity.this, "内容：" + article.author, Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initData() {
        for (int i = 0; i < 10; i++) {
            Article article = new Article("标题：" + i, "2021-07-1" + i, "zxx " + i);
            articleList.add(article);
        }
        adapter.notifyDataSetChanged();
    }
}